package com.denny.devdemo;

import java.util.ArrayList;
import java.util.List;

import com.denny.devdemo.clearer.worker.CheckBitmapActivity;
import com.denny.devdemo.drawArc.DownloadArcViewDemo;
import com.denny.devdemo.drawArc.DownloadRingActivity;
import com.denny.devdemo.sampleviewpager.SampleViewPagerAcitivy;
import com.denny.devdemo.sectionlist.SectionListActivity;
import com.denny.devdemo.touchevent.DispatcherTouchEventAcitivy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class MainActivity extends Activity {
	private ListView mListView ;
	private static List<String> mListData;
	static {
//		for(int i=0;i<10;i++){
//			if(mListData == null){
//				mListData = new ArrayList<String>();
//			}
//			mListData.add("Data"+i);
//		}
		if(mListData == null){
			mListData = new ArrayList<String>();
		}
		mListData.add("Sample ViewPager");
		mListData.add("dispatcher TouchEvent");
		mListData.add("SectionListView");
		mListData.add("DownloadArcView");
		mListData.add("验证图片文件");
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mListView = (ListView)findViewById(R.id.list_view);
		MyAdapter adapter = new MyAdapter(mListData);
		mListView.setAdapter(adapter);
		mListView.setOnItemClickListener(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	class MyAdapter extends BaseAdapter implements OnItemClickListener{

		private List<String> mData;
		public MyAdapter(List<String> data){
			mData = data;
		}
		@Override
		public int getCount() {
			return mData.size();
		}

		@Override
		public Object getItem(int position) {
			return mData.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			RelativeLayout layout = new RelativeLayout(MainActivity.this);
			TextView tv = new TextView(MainActivity.this);
			tv.setText(mData.get(position));
			tv.setTextSize(28);
			RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 100);
			params.addRule(RelativeLayout.CENTER_VERTICAL);
			layout.addView(tv, params);
			return layout;
		}
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			Intent intent = null;
			switch (position) {
			case 0://Sample ViewPager
				intent = new Intent(MainActivity.this,SampleViewPagerAcitivy.class);
				startActivity(intent);
				break;
			case 1://dispatcher Touchevent
				intent = new Intent(MainActivity.this,DispatcherTouchEventAcitivy.class);
				startActivity(intent);
				break;
			case 2://SectionListView
				intent = new Intent(MainActivity.this,SectionListActivity.class);
				startActivity(intent);
				break;
			case 3://DownloadArcView
				intent = new Intent(MainActivity.this,DownloadRingActivity.class);
				startActivity(intent);
				break;
			case 4://验证图片
                intent = new Intent(MainActivity.this,CheckBitmapActivity.class);
                startActivity(intent);
                break;
			default:
				break;
			}
			
		}
		
	}
}
